{% extends 'layout.html' %}
{% block title %}
    <title>员工列表</title>
{% endblock %}


{% block content %}
    <div style="margin-bottom: 15px">
        <a href="{% url 'emp_add' %}">
            <button type="button" class="btn btn-primary">新增</button>
        </a>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">员工列表</div>
        <div class="panel-body">
            <table class="table  table-striped">
                <tr>
                    <th>序号</th>
                    <th>工号</th>
                    <th>姓名</th>
                    <th>年龄</th>
                    <th>薪资</th>
                    <th>部门</th>
                    <th>操作</th>
                </tr>
                {% for emp in table_data %}
                    <tr>
                        <td>{{ forloop.counter }}</td>
                        <td>{{ emp.emp_no }}</td>
                        <td>{{ emp.emp_name }}</td>
                        <td>{{ emp.age }}</td>
                        <td>{{ emp.salary }}</td>
                        <td>{{ emp.dept.name }}</td>
                        <td>
                            {# /app08/dept/edit/{{ dept.id }}#}
                            <a href="{% url 'emp_edit' emp.id %}">
                                <button class="btn btn-primary">编辑</button>
                            </a>
                            <a href="{% url 'emp_delete' emp.id %}">
                                <button class="btn btn-danger">删除</button>
                            </a>
                        </td>
                    </tr>
                {% endfor %}
            </table>
            <span style="color: red">{{ request.session.error }}</span>
        </div>
    </div>
    <div style="text-align: center; position: relative; top: -20px">
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <li>
                    <a href="#">总条数:{{ total }}</a>
                </li>
                {% if has_pre_page %}
                    <li>
                        <a href="{% url 'emp_page' %}?page={{ pre_page }}" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
                {% endif %}

                {% for num in page_range %}
                    <li {% if page_num == num %}class="active"{% endif %}>
                        <a href="{% url 'emp_page' %}?page={{ num }}">{{ num }}</a>
                    </li>
                {% endfor %}

                {% if has_next_page %}
                    <li>
                        <a href="{% url 'emp_page' %}?page={{ next_page }}" aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                {% endif %}
                <li><a href="#">总页数:{{ pages }}</a></li>
            </ul>
        </nav>
    </div>
{% endblock %}